<template>
  <div id="app">
    <router-view></router-view>
    <van-tabbar v-model="active"  route v-show="$route.meta.showFooter">
      <van-tabbar-item to="/home" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item to="/fenlei" icon="search">分类</van-tabbar-item>
      <van-tabbar-item to="/cart" icon="shopping-cart-o" :badge="badge">购物车</van-tabbar-item>
      <van-tabbar-item to="/mine" icon="user-circle-o">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import {getcartapi} from "../src/api/cart"
export default {
  name: "App",
   computed: {
     badge:{
       get(){return this.$store.state.address.badge},
       set(){},
     },
  },
  data() {
    return {
      active: "home",
    };
  },
  methods:{
      //获取购物车列表
      async getcart() {
      const result = await getcartapi();
      console.log(result);
      this.cart = result;
      const cartlength=result;
      this. badge=cartlength.length;
      console.log(cartlength.length);
    },
 
    
  },
  created(){
    // const badge=localStorage.getItem("badge")||"";
    // this.$store.commit("address/changebadge", badge);
    // console.log(this.$store.state.address.badge);
    //数据同步持久化
     const token = localStorage.getItem("token") || "";
    console.log(token);
    this.$store.commit("setToken", token);
    const mobile=localStorage.getItem("mobile")||"";
    const idDefault=localStorage.getItem("idDefault")||"";
    const receiver = localStorage.getItem("receiver") || "";
    const regions = localStorage.getItem("regions") || "";
    const address = localStorage.getItem("address") || "";
    this.$store.commit("address/changereceiver", receiver);
    this.$store.commit("address/changeregions", regions);
    this.$store.commit("address/changeaddress", address);
     this.$store.commit("address/changemobile", mobile);
      this.$store.commit("address/changeidDefault", idDefault);
  }
};
</script>

<style></style>
